var t = require;
var e = module;
var o = exports;
var _n2,
    i =
        (this && this.__extends) ||
        ((_n2 = function n(t, e) {
            return (_n2 =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) {
                        Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
                    }
                })(t, e);
        }),
        function (t, e) {
            function o() {
                this.constructor = t;
            }
            _n2(t, e), (t.prototype = null === e ? Object.create(e) : ((o.prototype = e.prototype), new o()));
        });
Object.defineProperty(o, "__esModule", {value: !0});
var s = t("Common"),
    r = t("Global"),
    c = t("BaseSdk"),
    a = t("PlatfromDetailEnum"),
    u = t("PlatfromEnum"),
    l = (function (t) {
        function e() {
            var e = (null !== t && t.apply(this, arguments)) || this;
            return (
                (e._isRecorder = !1),
                (e._recorder = null),
                (e._recorderShareFunc = null),
                (e._videoPath = ""),
                (e._videoId = "30jer8ki7dnlojhdga"),
                (e._videoLoaded = !1),
                (e._videoOptions = null),
                (e._screenSpace = 12e3),
                (e._shopEnable = !1),
                (e._recorderTimer = null),
                (e._recorderTimerEnable = !1),
                (e._shareOptions = null),
                (e.gameName = null),
                (e.lastAdTime = 0),
                (e.lastScreenTime = 0),
                e
            );
        }
        return (
            i(e, t),
            (e.prototype.init = function () {
                var t = this;
                (this._recorderTimer = setInterval(function () {
                    t._recorderTimerEnable &&
                        t.getIsScreenRecordVideo() &&
                        t._recorderShareFunc &&
                        t._recorderShareFunc();
                })),
                    (this.lastAdTime = new Date().getTime()),
                    (this.lastScreenTime = new Date().getTime());
                var e = s.default.host + "/getConfig";
                this.sendHttpRequest(
                    e,
                    {app: "cfg_des_ball"},
                    function (e) {
                        if ("true" == e.config.stop) {
                            var o = new cc.Event.EventCustom("stopG", !1);
                            cc.director.dispatchEvent(o);
                        }
                        "true" == e.config.gravity &&
                            ((o = new cc.Event.EventCustom("gravityG", !1)), cc.director.dispatchEvent(o)),
                            "false" == e.config.mmyOpenUgc &&
                                t.getPlatFormDetail() == a.default.Mmy &&
                                ((o = new cc.Event.EventCustom("closeUgc", !1)), cc.director.dispatchEvent(o));
                    },
                    function () {}
                );
            }),
            (e.prototype.isOpenShare = function () {
                return !1;
            }),
            (e.prototype.login = function (t) {
                if (((this._loginOptions = t), 1 == t.type)) this.loginWithDouyin();
                else if (2 == t.type) {
                    var e = this.getAnonymousCode(),
                        o = {platform: u.default.ANDROID, openId: e, nickName: t.nickName};
                    this.doLogin(s.default.simpleLoginUrl, o);
                }
            }),
            (e.prototype.doLogin = function (t, e) {
                var o = this;
                this.sendHttpRequest(
                    t,
                    e,
                    function (t) {
                        if ((console.log("请求成功", t), t.ok))
                            if (0 == t.error) {
                                var e = t.data;
                                0 == e.user.status
                                    ? (console.log("登录完成，准备回调"), o._loginOptions.success(e))
                                    : (console.log("用户状态异常"),
                                      o._loginOptions.fail("你因违规操作,帐号已被系统冻结"));
                            } else o._loginOptions.fail(t.error);
                    },
                    function (t) {
                        console.log("request调用失败", t), o._loginOptions.fail("网络繁忙,请稍后再试");
                    }
                );
            }),
            (e.prototype.getAnonymousCode = function () {
                return jsb.reflection.callStaticMethod(
                    "org/cocos2dx/javascript/AppActivity",
                    "getAnonymousCode",
                    "()Ljava/lang/String;"
                );
            }),
            (e.prototype.loginWithDouyin = function () {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "loginWithDouyin", "()V");
            }),
            (e.prototype.dyTokenSuccess = function (t, e) {
                var o = {platform: u.default.ANDROID, openId: e, code: t};
                this.doLogin(s.default.dyLoginUrl, o);
            }),
            (e.prototype.loginError = function () {
                this._loginOptions.fail("登录失败");
            }),
            (e.prototype.createMoreGamesButton = function () {}),
            (e.prototype.getOpenDataContext = function () {
                return null;
            }),
            (e.prototype.postMessage = function (t) {
                console.log("推送开放数据", t);
            }),
            (e.prototype.startRecorder = function () {
                this._isRecorder = !0;
            }),
            (e.prototype.stopRecorder = function () {
                this._isRecorder = !1;
            }),
            (e.prototype.getRecorderState = function () {
                return this._isRecorder;
            }),
            (e.prototype.getIsScreenRecordVideo = function () {
                return !1;
            }),
            (e.prototype.shareRecorder = function (t) {
                var e = this;
                (this._recorderTimerEnable = !1),
                    this.getIsScreenRecordVideo()
                        ? ((this._shareOptions = t),
                          jsb.reflection.callStaticMethod(
                              "org/cocos2dx/javascript/AppActivity",
                              "shareRecord",
                              "(Ljava/lang/String;)V",
                              JSON.stringify([this.gameName])
                          ))
                        : this.stopRecorder(function () {
                              e.shareRecorder(t);
                          });
            }),
            (e.prototype.shareRecorderSuccess = function () {
                this._shareOptions && this._shareOptions.success && this._shareOptions.success();
            }),
            (e.prototype.shareRecorderFail = function () {
                this._shareOptions && this._shareOptions.fail && this._shareOptions.fail({errMsg: "player cancel"});
            }),
            (e.prototype.showBanner = function () {
                var t = new Date().getTime();
                !r.default.noAd &&
                    r.default.noAdTime < t &&
                    r.default.userInfo.maxChapter > 5 &&
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "setBannerShow", "(Z)V", !0);
            }),
            (e.prototype.hideBanner = function () {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "setBannerShow", "(Z)V", !1);
            }),
            (e.prototype.showCustomAd = function () {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "setFeedShow", "(Z)V", !0);
            }),
            (e.prototype.hideCustomAd = function () {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "setFeedShow", "(Z)V", !1);
            }),
            (e.prototype.showRewardVideo = function (t) {
                if (this.getVideoState()) {
                    var e = new Date().getTime();
                    (this.lastAdTime = e),
                        (this._videoOptions = t),
                        jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "playVideo", "()V");
                } else this.showToast("Advertising loading...");
            }),
            (e.prototype.playSurvey = function (t) {
                if (this.getSurveyState()) {
                    var e = new Date().getTime();
                    (this.lastAdTime = e),
                        (this._videoOptions = t),
                        jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "playSurvey", "()V");
                } else this.showToast("Survey loading...");
            }),
            (e.prototype.onVideoSuccess = function () {
                var t = this;
                (this.lastAdTime = new Date().getTime()),
                    setTimeout(function () {
                        t._videoOptions.success && t._videoOptions.success();
                    }, 500);
            }),
            (e.prototype.onVideoFail = function () {
                this._videoOptions.fail && this._videoOptions.fail();
            }),
            (e.prototype.getVideoState = function () {
                return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "getVideoStatus", "()I");
            }),
            (e.prototype.getSurveyState = function () {
                return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "getSurveyState", "()I");
            }),
            (e.prototype.playScreen = function (t) {
                void 0 === t && (t = 1);
                var e = new Date().getTime();
                !r.default.noAd &&
                    r.default.noAdTime < e &&
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "playScreen", "(I)V", t);
            }),
            (e.prototype.getLanguage = function () {
                return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "getLanguage", "()I");
            }),
            (e.prototype.sendEvent = function (t) {
                t &&
                    t.key &&
                    (t.value || (t.value = {}),
                    console.log("上报事件:", t.key),
                    jsb.reflection.callStaticMethod(
                        "org/cocos2dx/javascript/AppActivity",
                        "traceEvent",
                        "(Ljava/lang/String;Ljava/lang/String;)V",
                        t.key,
                        JSON.stringify(t.value)
                    ));
            }),
            (e.prototype.rating = function () {
                jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "rating", "()V");
            }),
            (e.prototype.showToast = function (t) {
                jsb.reflection.callStaticMethod(
                    "org/cocos2dx/javascript/AppActivity",
                    "showToast",
                    "(Ljava/lang/String;)V",
                    t
                );
            }),
            (e.prototype.vibrateShort = function () {
                this.shock(1);
            }),
            (e.prototype.vibrateLong = function () {
                this.shock(2);
            }),
            (e.prototype.shock = function (t) {
                try {
                    jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "shock", "(I)V", t);
                } catch (e) {
                    console.log("调用手机震动报错:" + e.message);
                }
            }),
            (e.prototype.setClipboardData = function (t) {
                try {
                    jsb.reflection.callStaticMethod(
                        "org/cocos2dx/javascript/AppActivity",
                        "copy",
                        "(Ljava/lang/String;)V",
                        t.data
                    ),
                        t.success && t.success();
                } catch (e) {}
            }),
            (e.prototype.setLocalStorage = function (t, e) {
                cc.sys.localStorage.setItem(this.gameName + t, e);
            }),
            (e.prototype.getLocalStorage = function (t) {
                return cc.sys.localStorage.getItem(this.gameName + t);
            }),
            (e.prototype.openGame = function () {
                console.log("打开游戏");
            }),
            (e.prototype.goBack = function () {}),
            (e.prototype.getShopDetails = function () {
                var t = jsb.reflection.callStaticMethod(
                    "org/cocos2dx/javascript/AppActivity",
                    "getShopDetails",
                    "()Ljava/lang/String;"
                );
                return JSON.parse(t);
            }),
            (e.prototype.resumePay = function () {}),
            (e.prototype.getUserInfo = function (t) {
                var e = {nickName: "Android用户"};
                "" != r.default.userInfo.nickName
                    ? (e.nickName = r.default.userInfo.nickName)
                    : this.getPlatFormDetail() == a.default.AdMob && (e.nickName = "Player"),
                    t.success && t.success(e, "");
            }),
            (e.prototype.pay = function (t) {
                console.log("拉取支付 key ", t.key),
                    (this._payOptions = t),
                    jsb.reflection.callStaticMethod(
                        "org/cocos2dx/javascript/AppActivity",
                        "launchPay",
                        "(Ljava/lang/String;)V",
                        t.key
                    );
            }),
            (e.prototype.onPaymentSuccess = function (t) {
                console.log("支付完成 key", t),
                    this._payOptions && this._payOptions.success && this._payOptions.success(t);
            }),
            (e.prototype.getLastAdTime = function () {
                return this.lastAdTime;
            }),
            (e.prototype.showPreVideo = function (t) {
                console.log("showPreVideo", t);
            }),
            (e.prototype.hidePreVideo = function () {
                console.log("hidePreVideo");
            }),
            (e.prototype.getShopEnable = function () {
                return this._shopEnable;
            }),
            (e.prototype.getPlatFormDetail = function () {
                return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "getPlatForm", "()I");
            }),
            e
        );
    })(c.default);
o.default = l;
